package com.leyou.item.service.impl;


import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 根据pid查询查询下一层的品牌分类
     *
     * @param pid
     * @return
     */
    @Override
    public List<Category> queryByParentId(Long pid) {
        Category category = new Category();
        category.setParentId(pid);
        List<Category> list = categoryMapper.select(category);
        return list;
    }

    /**
     * 编辑品牌,品牌的所属分类信息回显
     *
     * @param bid
     * @return
     */
    @Override
    public List<Category> queryByBrandId(Long bid) {
        List<Category> categories = this.categoryMapper.queryByBrandId(bid);
        return categories;
    }

    /**
     * 商品列表的名字查询
     *
     * @param asList
     * @return
     */
    @Override
    public List<String> queryNamesByIds(List<Long> asList) {
        ArrayList<String> names = new ArrayList<>();
        List<Category> categories = this.categoryMapper.selectByIdList(asList);
        categories.forEach(category -> {
            names.add(category.getName());
        });
        return names;
    }


}
